from typing import *


class Solution:
    def maxGoodNumber(self, nums: List[int]) -> int:

        ans = 0

        def f(s, v):
            if s == 7:
                nonlocal ans
                ans = max(ans, v)
                return
            for j in range(3):
                if (1 << j) & s == 0:
                    f(1 << j | s, v << nums[j].bit_length() | nums[j])

        f(0, 0)
        return ans


from functools import cache


class Solution:
    def maxGoodNumber(self, nums: List[int]) -> int:

        @cache
        def f(s):
            if s == 7:
                return 0
            ans = 0
            for j in range(3):
                if (1 << j) & s == 0:
                    cur = f(1 << j | s)
                    ans = max(ans, nums[j] << cur.bit_length() | cur)
            return ans

        return f(0)


so = Solution()
print(so.maxGoodNumber([1, 2, 3]))
# a = [1,2,3]
# for v in a:
#     print(v.bit_count())
